package org.mis6323.service.impl;

import org.mis6323.data.dao.PatientDao;
import org.mis6323.data.model.Patient;
import org.mis6323.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PatientServiceImpl implements PatientService {
    @Autowired
    private PatientDao patientDao;

    public void setPatientDao(PatientDao dao) {
        this.patientDao = dao;
    }
    
    public Patient lookUpPatient(String phoneNo) {
        if (phoneNo == null || phoneNo.isEmpty()) {
            throw new IllegalArgumentException("Empty phone number");
        }
        return patientDao.searchPatientByPhoneNo(phoneNo);
    }

    @Override
    public void createNewPatient(Patient patient) {
        if (patient == null) {
            throw new IllegalArgumentException("Patient cannot be null");
        }
        if (patient.getId() != null) {
            throw new IllegalArgumentException("Patient Id is not null");
        }
        this.patientDao.createPatient(patient);
    }

    @Override
    public void deletePatient(Long patientId) {
        if(patientId == null) {
            throw new IllegalArgumentException("Patient Id cannot be null");
        }
        this.patientDao.deletePatient(patientId);
    }

    @Override
    public void updatePatient(Patient patient) {
        if (patient == null) {
            throw new IllegalArgumentException("Patient cannot be null");
        }
        this.patientDao.updatePatient(patient);
    }

}
